package com.antler.smt.admin.service.impl;

import com.antler.smt.admin.mapper.PeopleInfoMapper;
import com.antler.smt.constant.PermissionConstant;
import com.antler.smt.entity.PeopleInfoEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.admin.PeopleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 人员信息操作
 *
 * @author zhangyi
 * @date 2018/7/17 11:36
 */
@Service
public class PeopleServiceImpl implements PeopleService {

    @Autowired
    private PeopleInfoMapper peopleInfoMapper;
    /**
     * 接受用户信息分页实体
     */
    Page<PeopleInfoEntity> peopleInfoEntities = null;
    /**
     * 返回当前专员下审核的用户列表
     *
     * @param userId
     * @return
     */
    @Override
    public Result peopleList(Long userId) {
        Result result = null;
        if(PermissionConstant.SUPER_ADMIN.equals(userId)){
            //超级管理员权限
            peopleInfoEntities = peopleInfoMapper.selectAllPeopleList();
        }else {
            //普通管理员
            peopleInfoEntities = peopleInfoMapper.selectPeopleListByUserId(userId);
        }
        if(peopleInfoEntities != null){
            result= new Result(new PageInfo<>(peopleInfoEntities));
        }else{
            result = new Result(ResultCodeEnum.APPEND_DATA_ERROR,"获取人员信息失败！");
        }
        return result;
    }
}
